package com.xidian.zhiancloud.controller.equipFacility.eqFacMng;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.xidian.zhiancloud.controller.base.BaseController;
import com.xidian.zhiancloud.dto.ResultDTO;
import com.xidian.zhiancloud.enums.GeneralResponseEnums;
import com.xidian.zhiancloud.model.DefendStandard;
import com.xidian.zhiancloud.model.OhStandard;
import com.xidian.zhiancloud.qo.equipFacility.DefendStandardQO;
import com.xidian.zhiancloud.qo.equipFacility.OhStandardQO;
import com.xidian.zhiancloud.service.equipFacility.DefendStandardService;
import com.xidian.zhiancloud.vo.equipFacility.DefendStandardVO;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Arrays;
import java.util.LinkedList;
import java.util.List;

/**
 * 维护标准
 */
@RestController
@RequestMapping("/DefendStandard")
public class DefendStandardController extends BaseController {
    @Autowired
    private DefendStandardService defendStandardService;


    /**
     * 批量增加维护标准
     * @param ids 设备设施的ids
     * @param defendStandard 维护标准
     * @return
     */
    @PostMapping("/add")
    public ResultDTO<Boolean> add(Long[] ids, DefendStandard defendStandard) {
        List<DefendStandard> list = new LinkedList<>();
        for (Long id : ids) {
            DefendStandard tmp = new DefendStandard();
            BeanUtils.copyProperties(defendStandard, tmp);
            tmp.setEqFacId(id);
            list.add(tmp);
        }
        return ResultDTO.successOf(defendStandardService.saveBatch(list), GeneralResponseEnums.SUCCESS);
    }


//    /**
//     * 新增
//     * @param defendStandard
//     * @return维护标准对象
//     */
//    @PostMapping("/add")
//    public ResultDTO<Boolean> add(DefendStandard defendStandard) {
//        Boolean result = defendStandardService.save(defendStandard);
//        return ResultDTO.successOf(result, GeneralResponseEnums.SUCCESS);
//    }
//
//    /**
//     * 根据id获取检修标准
//     *
//     * @param id 维护标准id
//     * @return 维护标准对象
//     */
//    @GetMapping("/getById")
//    public ResultDTO<DefendStandard> getById(@RequestParam("id") Long id) {
//        return ResultDTO.successOf(defendStandardService.getById(id), GeneralResponseEnums.SUCCESS);
//    }
//
//    /**
//     * 根据id删除维护标准
//     *
//     * @param ids ids数组
//     * @return 返回删除标志
//     */
//    @PostMapping("/deleteByIds")
//    public ResultDTO<Boolean> deleteByIds(Long[] ids) {
//        Boolean result = defendStandardService.removeByIds(Arrays.asList(ids));
//        return ResultDTO.successOf(result, GeneralResponseEnums.SUCCESS);
//    }
//
//    /**
//     * 根据id修改维护标准
//     *
//     * @param defendStandard 检修类型设置对象
//     * @return 返回修改状态
//     */
//    @PostMapping("/patchById")
//    public ResultDTO<Boolean> patchById(DefendStandard defendStandard) {
//        Boolean result = defendStandardService.updateById(defendStandard);
//        return ResultDTO.successOf(result, GeneralResponseEnums.SUCCESS);
//    }
//
//    /**
//     *
//     * @param defendStandardQO
//     * @return 分页列表
//     */
//    @GetMapping("/getListByQO")
//    public ResultDTO<IPage<DefendStandard>> getList(DefendStandardQO defendStandardQO) {
//        if (defendStandardQO.getCurrent()== null || defendStandardQO.getSize() == null) {
//            return ResultDTO.errorOf(GeneralResponseEnums.REQUEST_ERROR);
//        }
//        return ResultDTO.successOf(defendStandardService.selectByQO(defendStandardQO), GeneralResponseEnums.SUCCESS);
//    }
}
